<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<html:html>
<head>
<META http-equiv=Pragma content=no-cache>
<META http-equiv=Cache-Control content=no-cache>
<META http-equiv=Expires content=0>
<title><bean:message key="F0503.title"/></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="../../resource/css/style.css" type="text/css">
<script language="javascript" type="text/javascript" src="../../resource/js/util.js"></script>
<script language="javascript" type="text/javascript" src="../../resource/js/AdyhUtil.js"></script>
<script language="javascript" type="text/javascript" src="../../resource/calendar/DCDA_C03.js"></script>
<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/js/Validator.js"></script>
<script type="text/javascript"
		src="<%=request.getContextPath()%>/style/ext/adapter/ext/ext-base.js"></script>
	<script type="text/javascript"
		src="<%=request.getContextPath()%>/style/ext/ext-all.js"></script>
<script language="javascript1.2">

/**重置*/
function ResetMe()
{	
	document.getElementById("contractNum").className = "MyText";
    document.getElementById("invoiceNumber").className = "MyText";
	document.getElementById("manufacturingOrder").className = "MyText";
    document.getElementById("customersName").className = "MyText";
	document.getElementById("unitPrice").className = "MyText";
	document.getElementById("qty").className = "MyText";
	document.getElementById("totalRbm").className = "MyText";
	document.getElementById("totalUsd").className = "MyText";
	document.getElementById("totalEuros").className = "MyText";
	document.getElementById("invoiceDate").className = "MyText";
	document.getElementById("advancedInvoice").className = "MySelect";
	
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "none";
	objPrompt.innerHTML = "";
}

//保存 判断
function operation1(){
	ResetMe();
	var contractNum = document.getElementById("contractNum").value;
	var invoiceNumber = document.getElementById("invoiceNumber").value;
	var manufacturingOrder = document.getElementById("manufacturingOrder").value;
	var customersName = document.getElementById("customersName").value;
	var unitPrice = document.getElementById("unitPrice").value;
	var qty = document.getElementById("qty").value;
	var totalRbm = document.getElementById("totalRbm").value;
	var totalUsd = document.getElementById("totalUsd").value;
	var totalEuros = document.getElementById("totalEuros").value;
	var invoiceDate = document.getElementById("invoiceDate").value;
	var advancedInvoice = document.getElementById("advancedInvoice").value;
	var submitFlag = true;
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "block";
    objPrompt.innerHTML = "";
    	if(!isNotNull(Jtrim(contractNum))){
			objPrompt.innerHTML += "<li><bean:message key="F05.contractNumber"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("contractNum").className = "MyControlError";
			submitFlag = false;
		}
		else{
			if(isNumber(contractNum)){
				objPrompt.innerHTML += "<li><bean:message key="F05.contractNumber"/><bean:message key="adyh.error.number"/>！";
				document.getElementById("contractNum").className = "MyControlError";
				submitFlag = false;
			}
		}
		
		if(!isNotNull(Jtrim(invoiceNumber))){
			objPrompt.innerHTML += "<li><bean:message key="F05.invoiceNumber"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("invoiceNumber").className = "MyControlError";
			submitFlag = false;
		}
		else{
			if(isNumber(invoiceNumber)){
				objPrompt.innerHTML += "<li><bean:message key="F05.invoiceNumber"/><bean:message key="adyh.error.number"/>！";
				document.getElementById("invoiceNumber").className = "MyControlError";
				submitFlag = false;
			}
		}
		if(!isNotNull(Jtrim(manufacturingOrder))){
			objPrompt.innerHTML += "<li><bean:message key="common.ManufacturingOrder"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("manufacturingOrder").className = "MyControlError";
			submitFlag = false;
		}
		else{
			if(isNumber(manufacturingOrder)){
				objPrompt.innerHTML += "<li><bean:message key="common.ManufacturingOrder"/><bean:message key="adyh.error.number"/>！";
				document.getElementById("manufacturingOrder").className = "MyControlError";
				submitFlag = false;
			}
		}
		if(!isNotNull(Jtrim(customersName))){
			objPrompt.innerHTML += "<li><bean:message key="adyh.customerName"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("customersName").className = "MyControlError";
			submitFlag = false;
		}
		
		if(!isNotNull(Jtrim(unitPrice))){
			objPrompt.innerHTML += "<li><bean:message key="F05.unitPrice"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("unitPrice").className = "MyControlError";
			submitFlag = false;
		}
		else{
			if(isNumber(unitPrice)){
				objPrompt.innerHTML += "<li><bean:message key="F05.unitPrice"/><bean:message key="adyh.error.number"/>！";
				document.getElementById("unitPrice").className = "MyControlError";
				submitFlag = false;
			}
		}
		
		if(!isNotNull(Jtrim(qty))){
			objPrompt.innerHTML += "<li><bean:message key="adyh.quantity"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("qty").className = "MyControlError";
			submitFlag = false;
		}
		else{
			if(isNumber(qty)){
				objPrompt.innerHTML += "<li><bean:message key="adyh.quantity"/><bean:message key="adyh.error.number"/>！";
				document.getElementById("qty").className = "MyControlError";
				submitFlag = false;
			}
		}
		
		if(!isNotNull(Jtrim(invoiceDate))){
			objPrompt.innerHTML += "<li><bean:message key="F0503.invoicedDate"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("invoiceDate").className = "MyControlError";
			submitFlag = false;
		}
		
		if(!isNotNull(Jtrim(advancedInvoice))){
			objPrompt.innerHTML += "<li><bean:message key="F0503.advancedInvoice"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("advancedInvoice").className = "MyControlError";
			submitFlag = false;
		}
		
		if(!isNotNull(Jtrim(totalRbm))&&!isNotNull(Jtrim(totalUsd))&&!isNotNull(Jtrim(totalEuros))){
			objPrompt.innerHTML += "<li><bean:message key="adyh.sum"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("totalRbm").className = "MyControlError";
			document.getElementById("totalUsd").className = "MyControlError";
			document.getElementById("totalEuros").className = "MyControlError";
			submitFlag = false;
		}
		
		if(submitFlag==true){
		   document.forms[0].invoiceFlag.disabled =false;
		   if(document.forms[0].layOutType.value=="add"){
	           operation('insert');
	       }else{
	           operation('update');
	       }	
		}	      
}

//更改工作号 加载页面信息
  function changeDetail()
  {  		
      	var manufacturingOrder = document.getElementById("manufacturingOrder").value;
      	    	      
   		Ext.Ajax.request(
   		{
		url : 'F0503.do', 
		params : {operationType:'ajax',id:'manufacturingOrder',manufacturingOrder:manufacturingOrder},
		method: 'POST',
		success: function ( result, request) 
			{
			var reValue = "";
			var reValues = new Array();
			reValue = Jtrim(result.responseText);
			if(reValue ==""){
				alert("没有此工作号！");
				document.forms[0].customersCode.value = ""; 
	    		document.forms[0].customersName.value = "";
	    		document.forms[0].contractNum.value = ""; 
	    		document.forms[0].unitPrice.value = "";  
	    		document.forms[0].qty.value = "";  
	    		document.forms[0].totalRbm.value = "";  
	   			document.forms[0].invoiceFlag.value = "";
	   			document.forms[0].totalPrice.value = "";
				return;
			}
			reValues = reValue.split('*');
			document.forms[0].customersCode.value = reValues[0]; 
    		document.forms[0].customersName.value = reValues[1];
    		document.forms[0].contractNum.value = reValues[2]; 
    		document.forms[0].unitPrice.value = reValues[3];  
    		document.forms[0].qty.value = reValues[4];  
    		document.forms[0].totalRbm.value = reValues[5];  
    		document.forms[0].totalPrice.value = reValues[5];  
   			document.forms[0].invoiceFlag.value = reValues[6];  
   			
			},	
		failure: function ( result, request) { 
			alert("<bean:message key="F020106.title"/>");
			} 
		}
		);
  }
  
function initDetail(){

	var URL = "<%=request.getContextPath()%>/pages/F05/F0503.do?operationType=query&contractNum="+document.forms[0].contractNum.value;
	var ajaxTree = new ajax();
	ajaxTree.sendData("POST", URL, true, getReturnVal);		
		
}
function getReturnVal(xmlHttp){
	var reValue = "";
	var reValues = new Array();
	reValue = xmlHttp.responseText;
	if(reValue ==""){
		alert("<bean:message key="F0503.constractError"/>");
		return;
	}
	reValues = reValue.split('*');
	document.forms[0].customersCode.value = reValues[0]; 
    document.forms[0].customersName.value = reValues[1];
    document.forms[0].manufacturingOrder.value = reValues[2]; 
    document.forms[0].unitPrice.value = reValues[3];  
    document.forms[0].qty.value = reValues[4];  
    document.forms[0].totalRbm.value = reValues[5];  
	
}

function editInit(){

	if(document.forms[0].operationType.value == "edit"){
		document.getElementById("manufacturingOrder").className = "MyTextReadOnly";
		document.forms[0].manufacturingOrder.readOnly = true;
		//document.forms[0].groups.disabled = true;
	}
}

	function getMessage(){
		var errorMsg = document.forms[0].errorFlag.value;
		if ("" != errorMsg) {
		//**操作成功！*/
		if (errorMsg == 0) {
			alert("<bean:message key="common.alert1"/>");
		}
		//**操作失败！*/
		if (errorMsg == 1) {
			alert("<bean:message key="common.alert2"/>");
		}
		//**查询无结果！*/
		if (errorMsg == 2) {
			alert("<bean:message key="common.alert3"/>");
		}
		//**系统异常，请联系管理员！*/
		if (errorMsg == 3) {
			alert("<bean:message key="common.alert4"/>");
		}
		//**主键重复，保存失败！*/
		if (errorMsg == 4) {
			alert("<bean:message key="common.alert12"/>");
		}
		document.forms[0].errorFlag.value = "";
		}
	}
	
function ShowFormTitle(strTitle){
	document.write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"height:26px; background-position: left bottom; background-image: url(../../style/images/FormTitle_A_4.gif); background-repeat: repeat-x;\">");
	document.write("  <tr >");
	document.write("	<td style=\"width:5px; background-position: left bottom; background-image: url(../../style/images/FormTitle_A_1.gif); background-repeat: no-repeat;\">&nbsp;&nbsp;&nbsp;</td>");
	document.write("	<td class=\"FormTitle\" style=\"width:100%; padding-left:5px; padding-top:3px; background-position: left bottom; background-image: url(../../style/images/FormTitle_A_2.gif); background-repeat: no-repeat;\">");
	document.write("		<span id=\"spanFormTitle\" class=\"SpanTitle\">"+ strTitle +"</span>");
	document.write("	</td>");
	document.write("	<td style=\"width:5px; background-position: right bottom; background-image: url(../../style/images/FormTitle_A_3.gif); background-repeat: no-repeat;\">&nbsp;&nbsp;&nbsp;</td>");
    document.write("  </tr>");
	document.write("</table>");
}	

</script>
</head>

<body marginheight="0" marginwidth="0" bottommargin="0" topmargin="0" onLoad="javascript:editInit();getMessage();">
<html:form method="post" action="/pages/F05/F0503.do" enctype="multipart/form-data">
<html:hidden property="operationType"/>
<html:hidden property="layOutType" />
<html:hidden property="customersCode"/>
<html:hidden property="id"/>
<html:hidden property="totalPrice"/>
<html:hidden property="totalRbmOther"/>
<html:hidden property="errorFlag"/>
<!--Begin：表单标题-->
<div class="DivBlock">
	<script language="javascript" type="text/javascript">
		ShowFormTitle("<bean:message key="F0503.title"/>");
	</script>
</div>
<!--End：表单标题-->
<!--Begin：表单折叠区块1-->
<div class="DivBlock">
<div class="DivWrap">
  <table  WIDTH="81%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
	<tr>	
		<td align="center"><!--工作号码--><bean:message key="common.ManufacturingOrder"/></td>
		<td><html:text property="manufacturingOrder" styleClass="MyText" onchange="javascript:changeDetail();"/>
		<span class="Need">*</span></td>
		<td align="center"><!--订单号码--><bean:message key="F05.contractNumber"/></td>
		<td><html:text property="contractNum" styleClass="MyText" />
		<span class="Need">*</span></td>
		<td  align="center"><!--发票号码--><bean:message key="F05.invoiceNumber"/></td>
		<td><html:text property="invoiceNumber" styleClass="MyText" />
		<span class="Need">*</span></td>					
	</tr>
	<tr>
		<td align="center"><!--客户名称--><bean:message key="adyh.customerName"/></td>
		<td><html:text property="customersName" styleClass="MyTextReadOnly" readonly="true"/>
		<span class="Need">*</span></td>		
		<td align="center"><!--单价--><bean:message key="F05.unitPrice"/></td>
		<td><html:text property="unitPrice" styleClass="MyText"/>
		<span class="Need">*</span></td>
		<td align="center"><!--数量--><bean:message key="adyh.quantity"/></td>
		<td>
		<html:text property="qty" styleClass="MyText"/>
		<span class="Need">*</span></td>
	</tr>
	<tr>
	   <td align="center"><!--人民币--><bean:message key="adyh.rmb"/></td>
		<td><html:text property="totalRbm" styleClass="MyText"/></td>
		<td align="center"><!--美元--><bean:message key="adyh.usd"/></td>
		<td><html:text property="totalUsd" styleClass="MyText"/></td>
		<td align="center"><!--欧元--><bean:message key="adyh.euros"/></td>
		<td><html:text property="totalEuros" styleClass="MyText"/></td>
	</tr>
	<tr>
	   <td align="center"><!--开票时间--><bean:message key="F0503.invoicedDate"/></td>
		<td><html:text property="invoiceDate" styleClass="MyText" onclick="return CalendarClick(this)" />
		<span class="Need">*</span></td>
		<td align="center"><!--提前开票--><bean:message key="F0503.advancedInvoice"/></td>
		<td><html:select property="advancedInvoice" styleClass="MySelect">
		        <html:option value=""></html:option>
				<html:option value="0">否</html:option>
				<html:option value="1">是</html:option>
		</html:select>
		<span class="Need">*</span></td>
		<td align="center">是否自制</td>
		<td><html:select property="invoiceFlag" styleClass="MySelect" disabled="true">
		        <html:option value=""></html:option>
				<html:option value="0">否</html:option>
				<html:option value="1">是</html:option>
		</html:select>
		<span class="Need">*</span></td>
	</tr>
  </table>
</div>
</div>
<!--End：表单折叠区块1-->
<div class="DivBlock">
	<div class="DivButton">
	  <input type="button" name="Submit1" class="MyButton" value="<bean:message key="common.save"/>" onClick="javascript:operation1();">
	  <input type="button" name="Submit2" class="MyButton" value="<bean:message key="common.back"/>" onClick="javascript:operation('back');">
	</div>
	<div class="DivPrompt" id="divPrompt" style="display:none">
	</div>
</div>
</html:form>
</body>

</html:html>